#import wxPython and twitter
import wx
import twitter
import simplejson

class QuickTwitter(wx.Panel):
    initialClick = False
    api = twitter.Api(username='',password='')
    MAX_LENGTH = 140
    SUCCESS_MSG = "Tweet Sent!"
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)
        
        FontLabel = wx.Font(15, wx.SWISS, wx.NORMAL, wx.NORMAL, False, u'Arial')
        FontText = wx.Font(10, wx.MODERN, wx.NORMAL, wx.NORMAL, False, u'Arial')
        
        self.TweetButton =wx.Button(self, 10, "Tweet!", wx.Point(237, 150))
        self.LblName = wx.StaticText(self, -1, "What are you doing?",wx.Point(10,10))
        self.LblName.SetFont(FontLabel)
        self.LblNum = wx.StaticText(self,-1,str(self.MAX_LENGTH), wx.Point(285,15))
        self.LblNum.SetFont(FontText)
        self.LblSent = wx.StaticText(self,-1,"", wx.Point(10, 150))
        self.TxtTweet = wx.TextCtrl(self, -1, "Type in your Tweet.", \
            wx.Point(10, 35), wx.Size(300,100), style=wx.TE_MULTILINE)
        self.TxtTweet.SetMaxLength(self.MAX_LENGTH)
        self.TxtTweet.SetFont(FontText)
        self.TxtTweet.IsMultiLine()
        
        wx.EVT_BUTTON(self, 10, self.OnClick)
        wx.EVT_KEY_UP(self.TxtTweet, self.EvtChar)
        self.TxtTweet.Bind(wx.EVT_SET_FOCUS , self.OnFocusEditName, self.TxtTweet)

    def OnFocusEditName(self, event):
        if self.initialClick == False:
            self.TxtTweet.SetValue("")
            self.LblSent.SetLabel("")
            self.LblNum.SetLabel(str(self.MAX_LENGTH-len(self.TxtTweet.GetValue())))
            self.initialClick = True
        #print "focused"
    def OnClick(self,event):
        #print "tweet sent!"
        self.LblSent.SetLabel(self.SUCCESS_MSG)
        self.initialClick = False
        self.api.PostUpdate(self.TxtTweet.GetValue())
    def EvtChar(self, event):
        event.Skip()
        #print str(len(self.TxtTweet.GetValue()))
        self.LblNum.SetLabel(str(self.MAX_LENGTH-len(self.TxtTweet.GetValue())))

app = wx.PySimpleApp()
frame = wx.Frame(None, -1, " Quick Twitter",size=(335, 220))
QuickTwitter(frame,-1)
frame.Show(1)
app.MainLoop()
